/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.yonsei.iwb.smarttv.index;

import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.NodeIterator;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.rdf.model.Statement;
import com.hp.hpl.jena.rdf.model.StmtIterator;
import com.hp.hpl.jena.vocabulary.OWL;
import com.hp.hpl.jena.vocabulary.RDF;
import com.hp.hpl.jena.vocabulary.RDFS;
import edu.yonsei.iwb.smarttv.model.SMARTTVModel;
import java.util.Hashtable;

/**
 *
 * @author Onlyjiny
 */
public class IndexedDatatypeProperties extends Hashtable<Resource, String> {

    public static final String LABEL4DATATYPEPROPERTY = "label";

    public IndexedDatatypeProperties(SMARTTVModel tvModel) {
        Model model = tvModel.getJenaModel();
        UnindexedDatatypeProperties udp = new UnindexedDatatypeProperties();
        StmtIterator datatypePropertyList = model.listStatements(null, RDF.type, OWL.DatatypeProperty);
        while (datatypePropertyList.hasNext()) {
            String range = new String();
            Statement datatypeProperty = datatypePropertyList.nextStatement();
            Resource subject = datatypeProperty.getSubject();
            if (!udp.contains(datatypeProperty.getSubject())) {
                NodeIterator ni = model.listObjectsOfProperty(subject, RDFS.range);
                if (ni.hasNext()) {
                    range = ni.next().toString();
                } else {
                    range = "Undeclared";
                }
            } else {
                continue;
            }
            this.put(subject, range);
        }
    }
}
